/**
 * <pre>
 * @(#)MultiKeyedEntry.java 1.00 2009-11-9
 * 
 * Copyright (c) 1998, 2009 Regular Individual. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Contributor(s):
 *     Haixu Huang
 * </pre>
 **/
package cn.sh.huang.chart.ext.map;

/**
 * <pre>
 * MultiKeyedEntry ...
 * 
 * @version 1.0
 * </pre>
 */
public class MultiKeyedEntry implements Comparable
{
    private final Comparable[] keys;
    private Object value;

    MultiKeyedEntry(Comparable[] keys)
    {
        this.keys = keys;
    }

    public Object[] getKeys()
    {
        return this.keys;
    }

    public boolean equals(Object o)
    {
        if (o instanceof MultiKeyedEntry) {
            MultiKeyedEntry mk = (MultiKeyedEntry) o;
            if (mk.keys.length != keys.length) {
                return false;
            }
            for (int i = 0; i < keys.length; i++) {
                Object k = mk.keys[i];
                Object _k = keys[i];
                if (k != null && _k != null && !k.equals(_k)) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(Object o)
    {
        MultiKeyedEntry e = (MultiKeyedEntry) o;
        for (int i = 0; i < keys.length; i++) {
            int n = keys[i].compareTo(e.keys[i]);
            if (n != 0) {
                return n;
            }
        }
        return 0;
    }

    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < keys.length; i++) {
            sb.append(", ").append(keys[i]);
        }
        sb.append(": ").append(value);
        return sb.substring(2);
    }

    public void setValue(Object value)
    {
        this.value = value;
    }

    public Object getValue()
    {
        return value;
    }
}
